package com.mycompany.rest.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.mycompany.rest.domain.Reserva;
import com.mycompany.rest.domain.Reserva;

@Service("reservaService")
public class ReservaService {

	protected static Logger logger = Logger.getLogger("service");
	
	// In-memory list
	private List<Reserva> reservas = new ArrayList<Reserva>();
	
	public ReservaService() {
		logger.debug("Init database");
		
		// Create in-memory list
		Reserva r1= new Reserva();
		r1.setId((long)1);
		r1.setNombre("juan");
		
		Reserva r2= new Reserva();
		r2.setId((long)2);
		r2.setNombre("luis");
		
		reservas.add(r1);
		reservas.add(r2);
	}
	
	/**
	 * Retrieves all persons
	 */
	public List<Reserva> getAll() {
		logger.debug("Retrieving all persons");		
		return reservas;
	}
	
	/**
	 * Retrieves a single person
	 */
	public Reserva get( Long id ) {
		logger.debug("Retrieving person with id: " + id);
		
		for (Reserva reserva:reservas) {
			if (reserva.getId().longValue() == id.longValue()) {
				logger.debug("Found record");
				return reserva;
			}
		}
		
		logger.debug("No records found");
		return null;
	}
}
